#include "check_room.h"
#include <stdio.h>
#include <pthread.h>

int data_ready = 0;

int cond_func(void* param) {
    return data_ready != 0;
}

void* worker(void* arg) {
    check_room_t* cr = (check_room_t*)arg;

    printf("Worker: 等待条件...\n");
    int r = cr_wait_for(cr, cond_func, NULL, 5000);
    if(r == 1) {
        printf("Worker: 条件满足！\n");
    } else if(r == 0) {
        printf("Worker: 超时！\n");
    } else {
        printf("Worker: 错误！\n");
    }

    return NULL;
}

int main() {
    check_room_t* cr = cr_create();
    pthread_t th;
    pthread_create(&th, NULL, worker, cr);

    // 模拟 2 秒后数据准备好
    sleep(10);
    data_ready = 1;
    cr_notify(cr);

    pthread_join(th, NULL);
    cr_destroy(cr);
    return 0;
}

